package com.pzf.publish.scheduled;

import com.pzf.publish.config.RedisStreamConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;



/**
 * @Author: AdobePeng
 * @Date: 2021/3/11 14:59
 */
@Component
public class CleanStreamJob {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    @Autowired
    private RedisStreamConfig redisStreamConfig;


    @Scheduled(cron="0/5 * * * * ?")
    public void reportCurrentTime() {
        // 定时的清理stream中的数据，保留3条
        this.stringRedisTemplate.opsForStream().trim(redisStreamConfig.getStream(),3L);
//        // 定时的清理stream中的数据，保留3条左右，不少于3条
//        this.stringRedisTemplate.opsForStream().trim(redisStreamConfig.getStream(),3L,true);
    }
}
